﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace MyDiskInfo.DataStruct
{
    /// <summary>
    /// CPU信息
    /// </summary>
    [DataContract]
    public class CpuModel : INotifyPropertyChanged
    {
        private double _Load;
        /// <summary>
        /// CPU使用率
        /// </summary>
        [DataMember]
        public double Load
        {
            get { return _Load; }
            set
            {
                _Load = value;
                OnPropertyChanged("Load");
            }
        }

        private double _Clock;
        /// <summary>
        /// CPU频率
        /// </summary>
        [DataMember]
        public double Clock
        {
            get { return _Clock; }
            set
            {
                _Clock = value;
                OnPropertyChanged("Clock");
            }
        }

        private double _Temperature;
        /// <summary>
        /// CPU温度
        /// </summary>
        [DataMember]
        public double Temperature
        {
            get { return _Temperature; }
            set
            {
                _Temperature = value;
                OnPropertyChanged("Temperature");
            }
        }

        private double _Power;
        /// <summary>
        /// CPU电压
        /// </summary>
        [DataMember]
        public double Power
        {
            get { return _Power; }
            set
            {
                _Power = value;
                OnPropertyChanged("Power");
            }
        }

        /// <summary>
        /// CPU温度颜色
        /// </summary>
        public SolidColorBrush TemperatureColor
        {
            get
            {
                if (Math.Round(_Temperature) >= 100)
                {
                    return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ee0000"));
                }
                else if (Math.Round(_Temperature) >= 90)
                {
                    return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff0000"));
                }
                else if (Math.Round(_Temperature) >= 80)
                {
                    return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff9922"));
                }
                else if (Math.Round(_Temperature) >= 70)
                {
                    return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffff00"));
                }
                else if (Math.Round(_Temperature) >= 60)
                {
                    return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffff66"));
                }

                return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffffff"));
            }
        }

        /// <summary>
        /// CPU频率颜色
        /// </summary>
        public SolidColorBrush ClockColor
        {
            get
            {
                if (_Clock <= 0.6)
                {
                    return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ff0000"));
                }
                else if (_Clock < 1.0)
                {
                    return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffff00"));
                }
                else
                {
                    return new SolidColorBrush((Color)ColorConverter.ConvertFromString("#ffffff"));
                }
            }
        }

        #region INotifyPropertyChanged接口
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string name)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }
        #endregion

    }
}
